#!/bin/bash

set -eu

DEFAULT_JAVA_OPTS="-Xms512m -Xmx1024m -XX:+UseG1GC"
JAVA_OPTS=${JAVA_OPTS:-$DEFAULT_JAVA_OPTS}

APP_HOME=/app

JAR_FILE=$(ls ${APP_HOME}/*.jar | head -n 1)

if [ -z "$JAR_FILE" ]; then
  echo "Error: No JAR file found in $APP_HOME"
  exit 1
fi

echo "Starting application with JAVA_OPTS: $JAVA_OPTS"
echo "JAR file: $JAR_FILE"

exec java $JAVA_OPTS -jar "$JAR_FILE" "$@"